package modelo.bean;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;

import org.codehaus.jackson.annotate.JsonBackReference;
import org.codehaus.jackson.annotate.JsonManagedReference;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.ForeignKey;

@XmlRootElement
@Entity
public class Prova implements Serializable {

	public Prova() {
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;

	@Temporal(TemporalType.TIMESTAMP)
	private Date dataDaAplicaco;

	private String semestre;

	@ManyToMany(mappedBy = "listaDeProvas")
	private List<Aluno> listaDealunos;

	@ManyToOne
	@Fetch(FetchMode.JOIN)
	@ForeignKey(name = "fk_professor")
	@JoinColumn(name = "professor_id", referencedColumnName = "idprofessor", nullable = false)
	private Professor professor;

	@ManyToMany(cascade = CascadeType.ALL)
	@JoinTable(joinColumns = { @JoinColumn(name = "questao_id", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "prova_id", nullable = false, updatable = false) })
	@Fetch(FetchMode.JOIN)
	private List<Questao> listaDeQuestoes;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@JsonBackReference("professor-prova")
	public Professor getProfessor() {
		return professor;
	}

	public void setProfessor(Professor professor) {
		this.professor = professor;
	}

	@JsonManagedReference("prova-questao")
	public List<Questao> getListaDeQuestoes() {
		return listaDeQuestoes;
	}

	public void setListaDeQuestoes(List<Questao> listaDeQuestoes) {
		this.listaDeQuestoes = listaDeQuestoes;
	}

	public Date getDataDaAplicaco() {
		return dataDaAplicaco;
	}

	public void setDataDaAplicaco(Date dataDaAplicaco) {
		this.dataDaAplicaco = dataDaAplicaco;
	}

	public String getSemestre() {
		return semestre;
	}

	public void setSemestre(String semestre) {
		this.semestre = semestre;
	}

	@JsonBackReference("aluno-prova")
	public List<Aluno> getListaDealunos() {
		return listaDealunos;
	}

	public void setListaDealunos(List<Aluno> listaDealunos) {
		this.listaDealunos = listaDealunos;
	}

}
